#!/bin/bash

## date: 2025-0821

date=$(date +%y%m%d)
top_name=$1
path="/projects.SE032/cascade/workspace/xwqiu/PV/lvs"

##### check input file
if echo ${top_name} | grep -q "oasis"; then
    echo "this is OASIS file path!!"
    oasis_file=${top_name}
    ftype="OASIS"
elif echo ${top_name} | grep -q "gds"; then
    echo "this is GDSII file path!!"
    oasis_file=${top_name}
    ftype="GDSII"
else
    echo "this is top name!!"
    oasis_file="/projects.SE032/cascade/workspace/xwqiu/${top_name}/post.${date}/dataout/${top_name}.strm.${date}.oasis"
fi

##### 
oasis_top_name=`exec drvTopcell ${oasis_file}`
spi_file="/projects.SE032/cascade/workspace/xwqiu/PV/v2lvs/${top_name}.spi"
rule="${path}/rule/DFM_LVS_RC_CALIBRE_N6_1p13M_1X1Xa1Ya5Y2Yy2Z_ALRDL.1.0b"

##### run lvs
echo "LAYOUT PATH '${oasis_file}'"      >  ${path}/LVS.cal
echo "LAYOUT SYSTEM OASIS"              >> ${path}/LVS.cal
echo "LAYOUT PRIMARY ${oasis_top_name}" >> ${path}/LVS.cal
echo "SOURCE PATH '${spi_file}'"        >> ${path}/LVS.cal
echo "SOURCE PRIMARY ${oasis_top_name}" >> ${path}/LVS.cal
echo "SOURCE SYSTEM SPICE"              >> ${path}/LVS.cal
echo "VARIABLE POWER_NAME 'VDDC'"       >> ${path}/LVS.cal
echo "VARIABLE GROUND_NAME 'GNDC'"      >> ${path}/LVS.cal
echo "INCLUDE ${rule}"                  >> ${path}/LVS.cal

/apps/mentor/aoi_cal_2021.2_28.15/bin/calibre -lvs -hier -hyper -turbo 32 ${path}/LVS.cal | tee ${path}/LVS.log